package qinggui.mlz.smsservice.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import qinggui.mlz.module.utils.Response;
import qinggui.mlz.smsservice.service.SmsCrondService;
import qinggui.mlz.smsservice.service.SmsService;


import java.util.List;

@RestController
public class SmsController {
    @Autowired
    private SmsService smsService;
    @Autowired
    private SmsCrondService smsCrondService;

    /**
     * 发送短信
     *
     * @param phone 手机号
     * @return Response
     */
    @RequestMapping("sms/sendMessage")
    public Response<String> sendSms(@RequestParam String phone) {
        if (phone == null) {
            return new Response<>(4004, "手机号不能为空");
        }
        return new Response<>(1001, smsService.sendMessage(phone));
    }


    /**
     * 批量发送短信（多线程方式）
     *
     * @param phones 手机号
     * @return Response<String>
     */
    @RequestMapping("sms/batchSendMessage")
    public Response<String> batchSendMessage(@RequestParam List<String> phones) {
        if (phones == null || phones.isEmpty()) {
            return new Response<>(4004, "手机号不能为空");
        }
        return new Response<>(1001, smsService.sendBatchSms(phones));
    }

    /**
     * 异步发送短信业务
     *
     * @param phone 手机号
     * @return Response<String>
     */
    @RequestMapping("sms/cronSend")
    public Response<String> cronSend(@RequestParam String phone) {
        if (phone == null) {
            return new Response<>(4004, "手机号不能为空");
        }
        return new Response<>(1001, smsCrondService.cronSend(phone));
    }
}
